#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QApplication>
#include <QScreen>
#include <QQmlContext>
#include "mqttclientmanager.h"
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    qputenv("QT_LOGGING_RULES", QByteArray("qml=true"));
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    // 注册C++类给QML使用
    qmlRegisterSingletonInstance("qmtt.client.manager", 1, 0, "MQTTClientManager", MQTTClientManager::instance());
    engine.load(url);
    return app.exec();
}
